<?php

declare(strict_types=1);

namespace App\Model;

use App\Helpers\ConfigUtil;
use Hyperf\DbConnection\Model\Model;

/**
 *  服务费抽成日志
 */
class ServiceFeeLog extends Model
{
    protected $table = 'service_fee_log';

    const FEE_TYPE_CONSUME = 'consume';
    const FEE_TYPE_WITHDRAW = 'withdraw';

    /**
     * 添加消费抽成记录
     */
    static function addConsume($orderId = '', $coin = 0.0)
    {
        $model = new self();
        $model->order_id = $orderId;
        $model->fee_type = self::FEE_TYPE_CONSUME;
        $model->coin = $coin;
        $model->rate = ConfigUtil::getConsumeRate();
        $model->flag = 1;
        return $model->saveOrFail() ? 1 : 0;
    }

    /**
     * 添加提现抽成记录
     */
    static function addWithdraw($orderId = '', $coin = 0.0)
    {
        $model = new self();
        $model->order_id = $orderId;
        $model->fee_type = self::FEE_TYPE_WITHDRAW;
        $model->coin = $coin;
        $model->rate = ConfigUtil::getConsumeRate();
        $model->flag = 1;
        return $model->saveOrFail() ? 1 : 0;
    }
}
